04. Exercise: Create the ClippingExample Project
23 4 AAK Create Project SC
Exercise
In this exercise you are going to create the ClippingExample project.
Create a Kotlin project called
ClippingExamplewith the Empty Activity template. Usecom.example.androidfor the package name prefix.Open
MainActivity.kt.In the
onCreate()method, replace the default content view and set the content view to a new instance ofClippedView. This will be your custom view for the clipping examples that you will create next.
setContentView(ClippedView(this))
- At the same level as
MainActivity.kt, create a new Kotlin file and class for a custom view calledClippedViewthat extends View. The rest of your work will all be inside thisClippedView. The @JvmOverloads annotation instructs the Kotlin compiler to generate overloads for this function that substitute default parameter values.
class ClippedView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
}